package cn.tedu.jdbc;

import java.sql.*;
import java.util.Scanner;

/**
 * 登录功能
 * 用户输入用户名和密码
 * 返回结果
 * 登录成功
 * 登录错误
 * SELECT FROM
 */
public class JDBCLogin {
    public static void main(String[] args) {
        try (Connection connertion = DBUtil.getConnertion();) {
            Scanner scanner=new Scanner(System.in);
            System.out.println("用户名");
            String username=scanner.nextLine();
            System.out.println("密码");
            String password=scanner.nextLine();
            String sql="SELECT nickname FROM userinfo WHERE username=? AND password=?; ";
            PreparedStatement pr = connertion.prepareStatement(sql);
            pr.setString(1,username);
            pr.setString(2,password);
            ResultSet r = pr.executeQuery();
            if(r.next()){
                System.out.println("修改成功");
            }else{
                System.out.println("用户名或密码不存在");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
